package com.wms.exception;


import com.wms.bean.ResultBean;
import com.wms.core.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public ResultBean handlerException(Exception e){
        e.printStackTrace();
        log.error(e.getMessage());
        e.printStackTrace();
        return R.fail("服务器开小差了",e.getMessage());
    }
    @ExceptionHandler(ValidationException.class)
    public ResultBean handlerValidationException(ValidationException e){
        log.error(e.getMessage());
        log.error("验证失败:"+e.getErrorField());
        return R.fail("验证失败",e.getErrorField());
    }
    @ExceptionHandler(AutditException.class)
    public ResultBean handlerValidationException(AutditException e){
        log.error(e.getMessage());
        log.error("审核失败:"+e.getErrorField());
        return R.fail("审核失败",e.getErrorField());
    }
}
